package easy;

/**
 * 303. 区域和检索-数组不可变
 * 地址：https://leetcode.cn/problems/range-sum-query-immutable/
 */
public class 区域和检索_数组不可变_303 {
    int[] sums;
    public 区域和检索_数组不可变_303(int[] nums) {
        int n = nums.length;
        sums = new int[n+1];
        for(int i = 0; i < n; i++) {
            sums[i+1] = sums[i] + nums[i];
        }
    }

    public int sumRange(int left, int right) {
        return sums[right+1] - sums[left];
    }
}
